import request from "./request";
import { API_URL } from "../constants";
import type { IResponse, User } from "../types";

export function getToken(data: { username: string; password: string }) {
  return request<IResponse & { token: string }>(`${API_URL}/login`, {
    method: "post",
    data,
  });
}

export function getUserInfo(token: string, signal?: AbortSignal) {
  return request<
    IResponse & {
      user: User;
      roles: string[];
      permissions: string[];
    }
  >(`${API_URL}/getInfo`, {
    headers: {
      Authorization: token,
    },
    signal,
  });
}
